//824. 山羊拉丁文
//思路：就是整体的代码

#include <string.h>
#include <stdlib.h>
char * toGoatLatin(char * sentence){
    int hash[256] = {0};
    hash['a'] = 1, hash['e'] = 1, hash['i'] = 1, hash['o'] = 1,
    hash['u'] = 1, hash['A'] = 1, hash['E'] = 1, hash['I'] = 1,
    hash['O'] = 1, hash['U'] = 1;

    int len = strlen(sentence);
    int i = 0, count = 1;
    char* ret = (char*)malloc(sizeof(char)*2048);
    int pos = 0;//记录ret下标

    while(i < len)
    {
        int j = i;
        while(j<len && sentence[j] != ' ')
        {
            j++;
        }

        count++;//记录a的个数
        if(count != 2)//除了第一个单词，后面每个单词前放一个空格
        {
            ret[pos++] = ' ';
        }
        if(hash[sentence[i]])
        {
            memcpy(ret+pos, sentence+i, sizeof(char)*(j-i));
            pos += j-i;
            ret[pos++] = 'm';
            memset(ret+pos, 'a', count);
            pos += count;
        }
        else
        {
            memcpy(ret+pos, sentence+i+1, sizeof(char)*(j-i-1));
            pos += j-i-1;
            ret[pos++] = sentence[i];
            ret[pos++] = 'm';
            memset(ret+pos, 'a', count);
            pos += count;
        }

        i = j + 1;
    }
    ret[pos] = '\0';

    return ret;
}